#include "DaterBaseWindowManager.h"

template<> BaseWindowManager* Singleton<BaseWindowManager>::ms_Singleton = 0;

BaseWindowManager::BaseWindowManager()
{
}

BaseWindowManager::~BaseWindowManager()
{
	destroyAllBaseWindows();
}

void BaseWindowManager::addBaseWindow(BaseWindow* baseWindow)
{
	std::string name = baseWindow->getWindowName();

	_baseWindowRegistry[name] = baseWindow;
}

void BaseWindowManager::destroyBaseWindow(const std::string& name)
{
	BaseWindowRegistry::iterator pos = _baseWindowRegistry.find(name);
	if(pos != _baseWindowRegistry.end())
	{
		BaseWindow* baseWindow = pos->second;
		_baseWindowRegistry.erase(pos);

		delete baseWindow;
	}
}

void BaseWindowManager::destroyBaseWindow(BaseWindow* baseWindow)
{
	if(baseWindow)
	{
		std::string name = baseWindow->getWindowName();
		destroyBaseWindow(name);
	}
}

BaseWindow* BaseWindowManager::getWindow(const std::string& name)
{
	BaseWindowRegistry::const_iterator pos = _baseWindowRegistry.find(name);

	if (pos == _baseWindowRegistry.end())
	{
	//exception! the event does not exist.
	}

	return pos->second;
}

bool BaseWindowManager::isBaseWindowPresent(const std::string& name)
{
	return (_baseWindowRegistry.find(name) != _baseWindowRegistry.end());
}

void BaseWindowManager::destroyAllBaseWindows(void)
{
	std::string baseWindow_name;
	while (!_baseWindowRegistry.empty())
	{
		baseWindow_name = _baseWindowRegistry.begin()->first;
		destroyBaseWindow(baseWindow_name);
	}
}